package com.du.ssm.service;

import com.du.ssm.mapper.EmployeeMapper;
import com.du.ssm.pojo.Department;
import com.du.ssm.pojo.Employee;
import com.du.ssm.pojo.EmployeeExample;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author : DuJiabao
 * @Project : ssm
 * @Time : 2021/4/11 18:47
 * @Desc :
 */
@Service
public class EmployeeService {
  EmployeeMapper employeeMapper;

  public void updateEmp(Employee employee) {
    employeeMapper.updateByPrimaryKeySelective(employee);
  }
  /**
   * 检查用户名是否已经存在
   * @param empName
   * @return
   */
  public boolean checkEmpName(String empName) {
    EmployeeExample employeeExample = new EmployeeExample();  // 新建一个例子
    EmployeeExample.Criteria criteria = employeeExample.createCriteria();  // 把条件的引用拿出来
    criteria.andEmpNameEqualTo(empName);  // 添加条件
    long count = employeeMapper.countByExample(employeeExample); // 调用方法
    return count == 0;
  }

  public int insertEmployee(Employee employee) {
    return employeeMapper.insertSelective(employee);
  }

  public List<Employee> getAllEmployees() {
    return employeeMapper.selectByExampleWithDept(null);
  }

  @Autowired
  public void setEmployeeMapper(EmployeeMapper employeeMapper) {
    this.employeeMapper = employeeMapper;
  }
}
